<template>
    <el-dialog v-model="props.dialogVisible" :title="props.title" width="60%" :before-close="beforeClose">
        <el-form :model="props.dialogForm" 
        :label-position="props.dialogConfig.labelPosition ?? 'right'" 
        :label-suffix="props.dialogConfig.labelSuffix ?? ''"
        :size="props.dialogConfig.size ?? 'default'" 
        style="width: 100%"
        :label-width="props.dialogConfig.labelWidth ?? '60px'">
            <el-row :gutter="props.dialogConfig.gutter ?? 16">
                <el-col v-for="item in props.formItemList" :key="item.prop" :xs="item.xs ?? 24" :sm="item.sm ?? 24" :md="item.md ?? 12" :lg="item.lg ?? 12" :xl="item.xl ?? 12">
                    <el-form-item :label="item.label" :prop="item.prop">
                        <el-input v-model="props.defaultForm[item.prop]" :placeholder="item.placeholder ?? '请输入'" v-if="item.inputType === 'input'" style="width: 100%" />
                        <el-select v-model="props.defaultForm[item.prop]" :placeholder="item.placeholder ?? '请选择'" v-if="item.inputType === 'select'" style="width: 100%">
                            <el-option v-for="key in item.option" :value="key.value" :key="key.value" :label="key.label" />
                        </el-select>
                        <el-input type="textarea" v-if="item.inputType === 'textarea'" style="width: 100%" />
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <template #footer>
            <div class="footer">
                <el-button type="primary" @click="enterDialog" :loading="props.dialogConfig.buttonLoading">确 定</el-button>
                <el-button @click="cancelDialog">取 消</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup>
const props = defineProps({
    dialogConfig: {
        type: Object,
        default: {}
    },
    dialogVisible: {
        type: Boolean,
        default: false
    },
    title: {
        type: String,
        default: ''
    },
    formItemList: {
        type: Array,
        default: []
    },
    defaultForm: {
        type: Object,
        default: {}
    }
})
const emit = defineEmits(['cancelDialog', 'enterDialog'])
const enterDialog = () => {
    emit('enterDialog', { form: props.defaultForm, type: props.dialogConfig.operation })
}
const cancelDialog = () => {
    emit('enterDialog')
}
const beforeClose = () => {
    emit('enterDialog')
}
</script>
<style lang="less" scoped>
/** @import url(~/assets/index.less); */
</style>